#include "AbstractCommand.h"
#include "Common/Core.h"

using namespace Command;

AbstractCommand::AbstractCommand(const QString& name)
{
	setName(name);
}

Common::Core* AbstractCommand::core() const
{
	return _core;
}

const Common::Core*AbstractCommand::coreConst() const
{
	return _core;
}

void AbstractCommand::sendData(quint8 msgType, const QByteArray& body)
{
	QByteArray logData = body;
	logData.insert(0, msgType);

	setLogAfterExecute(">> " + logData);

	qDebug() << "SendData[" << logData.size() << "]: " << logData.toHex();

	_core->transport()->sendMessage(logData);
}

void AbstractCommand::setName(const QString& name)
{
	_name = name;
}

void AbstractCommand::setLogAfterExecute(const QString& log)
{
	_logAfterExecute = log;
}

void AbstractCommand::setLogAfterResponse(const QString& log)
{
	_logAfterResponse = log;
}

void AbstractCommand::execute(Common::Core* core)
{
	_core = core;
	execute();
}

QString AbstractCommand::name() const
{
	return _name;
}

QString AbstractCommand::logAfterExecute() const
{
	return _logAfterExecute;
}

QString AbstractCommand::logAfterResponse() const
{
	return _logAfterResponse;
}
